package com.soundShape.mediators.menu
{
	
	import com.soundShape.constants.SoundShapesInfo;
	import com.soundShape.events.SoundShapeEvent;
	import com.soundShape.mediators.AbstractViewMediator;
	import com.soundShape.model.ApplicationModel;
	import com.soundShape.views.menu.Menu;
	import com.soundShape.views.newEmployee.NewEmployee;
	import com.soundShape.vo.EmployeeVO;
	
	import flash.desktop.NativeApplication;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.effects.Move;
	import mx.effects.Rotate;
	import mx.events.FlexEvent;
	import mx.events.ValidationResultEvent;
	import mx.managers.PopUpManager;
	import mx.validators.ValidationResult;
	
	import spark.components.BorderContainer;
	import spark.components.Button;
	import spark.components.TextInput;
	import spark.effects.Move;
	import spark.effects.easing.Bounce;
	import spark.effects.easing.EaseInOutBase;
	import spark.effects.easing.Elastic;
	import spark.utils.TextFlowUtil;
	
	
	public class MenuMediator extends AbstractViewMediator
	{
		
		public var isInitLogin:Boolean = true;	
		
		
		
					
				public function MenuMediator()
				{
					super(Menu);
				}
				
				/**
				 * Since the AbstractViewMediator sets the view via Autowiring in Swiz,
				 * we need to create a local getter to access the underlying, expected view
				 * class type.
				 */
				public function get view():Menu
				{
					return this._view as Menu;
				}
				
				/**
				 * The <code>init()</code> method is fired off automatically by the 
				 * AbstractViewMediator when the creation complete event fires for the
				 * corresponding ViewMediator's view. This allows us to listen for events
				 * and set data bindings on the view with the confidence that our view
				 * and all of it's child views have been created and live on the stage.
				 */
				override protected function init():void
				{
					super.init();
					
					this.setViews();
					
					//soundWaves eye candy
					doSoundWaves();
					
				}
				
				override protected function setViewDataBindings():void
				{
					super.setViewDataBindings();
					
				}	
				
				override protected function setViewListeners():void
				{
					super.setViewListeners(); 
					
					this.view.soundShapeCircles.addEventListener(SoundShapeEvent.CIRCLES_COMPLETE, handleCirclesComplete);
					
				}
				
				protected function handleCirclesComplete(event:Event):void
				{
					
					var soundShapeEvent:SoundShapeEvent;
					soundShapeEvent = new SoundShapeEvent(SoundShapeEvent.SHOW_SLIDING_MENU);
					this.dispatcher.dispatchEvent(soundShapeEvent);
					
					if(this.applicationModel.isInit)
					{
						soundShapeEvent = new SoundShapeEvent(SoundShapeEvent.SHOW_INFO);
						soundShapeEvent.data = {type:MouseEvent.MOUSE_OVER, id:"btnMainMenu"};
						this.dispatcher.dispatchEvent(soundShapeEvent);
						this.applicationModel.isInit = false;
					}
					
				}				
				
				
				private function setViews():void
				{
					
				}
				
				
				
				/**
				 * *******************************************************************************
				 * Handlers
				 * *******************************************************************************
				 */
				
				private function handleMenuEvent(mouseEvent:MouseEvent):void
				{
					switch(Button(mouseEvent.currentTarget).id)
					{
						case "btnMainMenu":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_MENU_VIEW));
							break;
						
						case "btnAdmin":
							//this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_ADMIN_VIEW));
							break;
						
						case "btnFollowUp":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_FOLLOW_UP_VIEW));
							break;
						
						case "btnFreeConsultation":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_FREE_CONSULTATION_VIEW));
							break;
						
						case "btnNewCustomer":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_NEW_CUSTOMER_VIEW));
							break;
						
						case "btnManagePhoto":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_PHOTOS_VIEW));
							break;
						
						case "btnTransaction":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_TRANSACTIONS_VIEW));
							break;
						
						case "btnTreatment":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_TREATMENT_VIEW));
							break;
						
						case "btnReporting":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_REPORTING_VIEW));
							break;
					
						case "btnComparison":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_COMPARISON_VIEW));
							break;
						
						case "btnSpecialDates":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_SPECIAL_DATES_VIEW));
							break;
					}
				}
				
				private function handleBtnLogin(mouseEvent:MouseEvent):void
				{
					this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_LOGIN_VIEW));
				}
				
				
				private function doInfo(id:String):void
				{
					this.view.soundShapeCircles.alpha = 0.3;
					
					switch(id)
					{
						
						case "btnMainMenu":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.mainMenuInfo);
							break;
						
						case "btnNewCustomer":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.newCustomerInfo);
							break;
						
						case "btnTreatment":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.treatmentInfo);
							break;
						
						case "btnManagePhoto":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.photoInfo);
							break;
						
						case "btnComparison":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.comparisonInfo);
							break;
						
						case "btnAdmin":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.adminInfo);
							break;
						
						case "btnSpecialDates":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(SoundShapesInfo.specialDatesInfo);
							break;
						
					}
				}
				
				
				private function doSoundWaves():void
				{
					this.view.soundShapeCircles.alpha = 1.0;
					this.view.soundShapeCircles.doCircles(true);
				}
				
				
				
				
				/**
				 * *******************************************************************************
				 * Swiz EventHandlers
				 * *******************************************************************************
				 */
				[EventHandler(event="SoundShapeEvent.SHOW_INFO")]
				public function doLoginResult(soundShapeEvent:SoundShapeEvent):void
				{
					var type:String = soundShapeEvent.data.type;
					var id:String = soundShapeEvent.data.id;
					
					switch(type)
					{
						case MouseEvent.MOUSE_OVER:
							this.view.txtArea.visible = true;
							doInfo(id);
							break;
						
						case MouseEvent.MOUSE_OUT:
							this.view.txtArea.visible = false;
							//this.view.soundShapeCircles.alpha = 1.0;
							break;
					
					}
				}
				
				[EventHandler(event="SoundShapeEvent.RESET_TEXT_INFO")]
				public function resetTextInfo(soundShapeEvent:SoundShapeEvent):void
				{
					this.view.txtArea.text = "";
				}
		}
		
	}
